package vn.edu.fpt.xml.back.apis.news;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import vn.edu.fpt.xml.back.daos.ArticleDao;
import vn.edu.fpt.xml.back.dtos.news.ArticleEntities;
import vn.edu.fpt.xml.back.services.news.NewsProviderService;

import javax.annotation.Resource;
import javax.transaction.Transactional;

/**
 * Created by hiephn on 2014/04/29.
 */
@Service
@RequestMapping("/news/poster")
public class NewsPosterApi {

    @Resource(name = "newsProviderService")
    protected NewsProviderService newsProviderService;

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
    public String defaultPage() {
        return "News Poster default page";
    }

    @ResponseBody
    @RequestMapping(value = "article",
            method = RequestMethod.POST
//            consumes = MediaType.APPLICATION_XML_VALUE,
//            produces = MediaType.APPLICATION_XML_VALUE
    )
    public String postArticle(@RequestBody ArticleEntities articleEntities) {

        newsProviderService.persistArticle(articleEntities);

        return "<status>OK</status>";
    }

    @ResponseBody
    @RequestMapping(value = "articleString",
            method = RequestMethod.POST
//            produces = MediaType.APPLICATION_XML_VALUE
    )
    public String postArticleString(@RequestBody String articleEntities) {

//        articleDao.save(articleEntity);

        return articleEntities;
    }
}
